/**
 * Created by Shiun on 2018/5/7.
 */

$(function () {
    $('#login-btn').on('click', function () {
        var username = $.trim($('[name="username"]').val());
        var password = $.trim($('[name="password"]').val());


        if(!username){
            mui.toast("请输入用户名");
            return;
        }

        if(!password){
            mui.toast("请输入密码");
            return;
        }

        $.ajax({
            url:' /user/login',
            type:'post',
            data:{
                username:username,
                password:password
            },
            success: function (res) {
                if(res.error==403){
                    mui.toast("账号或密码不正确");
                    $('#login-btn').html("登录");
                    //console.log(result);
                }else {
                    as = res.success;
                    mui.toast("登录成功");
                    console.log(res);
                    //$('#login-btn').html("登录");
                    setTimeout(function () {
                        location.href = "user.html";
                    },2000)
                }
            },
            beforeSend: function () {
                    $('#login-btn').html("正在登录...");
            }
        })
    })
})
